﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Ershou.BLL;
using QRCoder;
using System.Drawing;
using ZXing;
using ZXing.QrCode;
using System.Drawing.Imaging;

public partial class jiaona : System.Web.UI.Page
{
    public sp sp1 = new sp();
    protected void Page_Load(object sender, EventArgs e)
    {

        string content = "一共缴纳"+sp1.select3(int.Parse(Request.QueryString["ID"])); // 替换为您想要生成二维码的内容
        Bitmap qrCodeBitmap = GenerateQRCode(content, 200, 200); // 生成二维码Bitmap
        Image1.ImageUrl = ConvertBitmapToImageUrl(qrCodeBitmap);
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        sp1.Insert(Convert.ToInt32(Session["CustomerId"]), int.Parse(Request.QueryString["ID"]),int.Parse(Session["monkey"].ToString().Trim()));
        Response.Redirect("~/spck.aspx?ID=" + Request.QueryString["ID"]);
    }
    private Bitmap GenerateQRCode(string content, int width, int height)
    {
        QRCodeGenerator qrGenerator = new QRCodeGenerator();
        QRCodeData qrCodeData = qrGenerator.CreateQrCode(content, QRCodeGenerator.ECCLevel.Q); // 正确引用ECCLevel
        QRCode qrCode = new QRCode(qrCodeData);

        // 假设您想要使用黑色和白色
        Color darkColor = Color.White; // 暗色部分使用黑色
        Color lightColor = Color.Black; // 亮色部分使用白色

        return qrCode.GetGraphic(width, lightColor, darkColor, true);
    }

    private string ConvertBitmapToImageUrl(Bitmap bitmap)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            bitmap.Save(ms, ImageFormat.Png); // 将Bitmap保存到MemoryStream中
            byte[] imageBytes = ms.ToArray(); // 将MemoryStream转换为字节数组

            // 将字节数组转换为Base64字符串
            string base64String = Convert.ToBase64String(imageBytes);
            return "data:image/png;base64," + base64String; // 返回Base64编码的图像URL
        }
    }
}